#ifndef __I2C_H__
#define __I2C_H__
#include "type.h"

#define NON_REENTRANT

/**
 * PROCESS MODE
 * 0=polling
 * 1=interrupt
 */
#define I2C1_MASTER    0
#define I2C1_SLAVE      1

#define I2C1_MODE I2C1_SLAVE

#define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000)
#define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT))
#define I2C1_SLAVE_ADDR      0x30
//#define I2C_EEPROM_ADDR     0xA0


typedef enum
{
    FAILED = 0,
    PASSED = !FAILED
} Status;

typedef enum
{
    C_READY = 0,
    C_START_BIT,
    C_STOP_BIT
}CommCtrl_t;

typedef enum
{
    MASTER_OK = 0,
    MASTER_BUSY,
    MASTER_MODE,
    MASTER_TXMODE,
    MASTER_RXMODE,
    MASTER_SENDING,
    MASTER_SENDED,
    MASTER_RECVD,
    MASTER_BYTEF,
    MASTER_BUSERR,
    MASTER_UNKNOW,
    SLAVE_OK = 20,
    SLAVE_BUSY,
    SLAVE_MODE,
    SLAVE_BUSERR,
    SLAVE_UNKNOW,

}ErrCode_t;

#define MODULE_SELF_RESET       1
#define MODULE_RCC_RESET        2
#define SYSTEM_NVIC_RESET       3
#define COMM_RECOVER_MODE       0

MI_BOOL i2c2_master_init(void);
MI_BOOL i2c2_master_send_bytes_by_addr(MI_U8 slave_addr,MI_U8 reg_addr,MI_U8 *w_data,MI_U16 len);
MI_BOOL i2c2_master_receive_bytes_by_addr(MI_U8 slave_addr,MI_U8 reg_addr,MI_U8 *r_data,MI_U16 len);

#if I2C1_MODE == I2C1_SLAVE
MI_BOOL i2c1_slave_init(void);
#else
MI_BOOL i2c1_master_init(void);
MI_BOOL i2c_master_send_bytes_by_addr(MI_U8 slave_addr,MI_U8 reg_addr,MI_U8 *w_data,MI_U16 len);
MI_BOOL i2c_master_receive_bytes_by_addr(MI_U8 slave_addr,MI_U8 reg_addr,MI_U8 *r_data,MI_U16 len);

#endif
#endif